import React, { useEffect, useState } from 'react';

function Zhuti() {
    const [theme,setTheme]=useState(()=>{
        const save=localStorage.getItem('theme')
        return save?save:'light'
    })
    useEffect(()=>{
        document.body.setAttribute('data-theme',theme)
        localStorage.setItem('theme',theme)
    },[theme])
    const an=()=>{
        setTheme(theme==='light'?'dark':'light')
    }
    return (
        <div>
            <button onClick={an}>{theme==='light'?'白天':'黑夜'}</button>
        </div>
    );
}

export default Zhuti;